package com.atguigu.gmall.product.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 商品管理 rabbit 配置类
 */
@Configuration
public class ProductRabbitConfig {
    /**
     * 配置商品管理交换机
     * @return
     */
    @Bean("productExchange")
    public Exchange productExchange(){
        return ExchangeBuilder.directExchange("product_exchange").build();
    }

    /**
     * 配置商品上架消息队列
     * @return
     */
    @Bean("upperQueue")
    public Queue upperQueue(){
        return QueueBuilder.durable("upper_queue").build();
    }

    /**
     * 商品上架绑定配置
     * @param productExchange
     * @param upperQueue
     * @return
     */
    @Bean("upperBinding")
    public Binding upperBinding(@Qualifier("productExchange") Exchange productExchange ,
                                  @Qualifier("upperQueue") Queue upperQueue){
        return BindingBuilder.bind(upperQueue).to(productExchange).with("sku_upper").noargs();
    }

    /**
     * 配置商品下架消息队列
     * @return
     */
    @Bean
    public Queue downQueue(){
        return QueueBuilder.durable("down_queue").build();
    }

    /**
     * 商品下架绑定配置
     * @param productExchange
     * @param downQueue
     * @return
     */
    @Bean
    public Binding downBinding(@Qualifier("productExchange") Exchange productExchange ,
                                  @Qualifier("downQueue") Queue downQueue){
        return BindingBuilder.bind(downQueue).to(productExchange).with("sku_down").noargs();
    }
}
